function findLongestSubstr(str) {
  // write code here
  let length = str.length;
  let dp = new Array(length).fill("");
  let t = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] == str[i + 1]) {
      dp[t] += str[i];
    } else {
      dp[t] += str[i];
      t++;
    }
  }

  let maxlen = 0;
  let res = "";
  for (let i = 0; i < t; i++) {
    if (dp[i].length > maxlen) {
      maxlen = dp[i].length;
      res = dp[i];
    }
  }
  return res;
}
let res = findLongestSubstr("ssssssssssssssshhhhopeeeeeeee");
console.log(res);
